<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page errorPage="../error/404.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>友情链接列表</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
<meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
<meta name="format-detection" content="telephone=no">
<link rel="shortcut icon" href="/images/favicon.png">
<link rel="stylesheet" href="/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="/css/font_eolqem241z66flxr.css"
	media="all" />
<link rel="stylesheet" href="/css/list.css" media="all" />  
</head>
<body class="childrenBody">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend style="text-align: center">${admin.realname}博客</legend>
</fieldset>
	<blockquote class="layui-elem-quote news_search">
		<form class="layui-form">
			
			<div style="margin-top: 1%">
				
				
		
				
			
				
					<div class="layui-inline">
						<a class="layui-btn layui-btn-danger batchDel">批量删除</a>
					</div>
				
				
			</div>
	</blockquote>
	</form>
	<div class="layui-form">
		<table id="LinkList" lay-filter="LinkList"></table>
	</div>
	<script type="text/javascript" src="/layui/layui.js"></script>
	<script type="text/html" id="barEdit">
  		<a class="layui-btn layui-btn-xs" lay-event="edit">审核</a>
  		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>
		<script type="text/html" id="statusTpl">
 		 {{#  if(d.isview === 1){ }}
   		 <span style="color: #FFB800;">待审核</span>
  		{{#  } else if(d.isview ===2){ }}
			<span style="color: #01AAED;">已审核</span>
		{{#  } }}
   		
  	
	</script>
		
	<script>
		layui
				.config({
					base : "js/"
				})
				.use(
						[ 'form', 'layer', 'jquery', 'table', 'laydate' ],
						function() {
							var form = layui.form, table = layui.table, layer = parent.layer === undefined ? layui.layer
									: parent.layer, laydate = layui.laydate
									$ = layui.jquery,
									nowTime = new Date().valueOf(),
									max = null
									

							//加载页面数据
							table
									.render({
										id : 'LinkList',
										elem : '#LinkList',
										url : '/link/getLinkListByNotIsView' //数据接口
										,
										limit : 10//每页默认数
										,
										limits : [ 10, 20, 30, 40 ],
										cols : [ [ //表头
												{
													type : 'checkbox'
												},
												{
													field : 'id',
													title : '友情链接编号',
													width : 60
												},
												{
													field : 'lname',
													title : '友情链接名称'
												},
												{
													field : 'lpath',
													title : '友情链接地址',
													templet:'<div><a href="{{d.lpath}}">{{d.lname}}</a></div>'
												},
												{
													field : 'ldes',
													title : '友情链接说明'
													
												}, 	{
													field : 'uppid',
													title : '优秀程度'
													
												}, 	{
													field : 'adminurl',
													title : '站长推荐'
													
												}, {
													field : 'isview',
													title : '是否审核',
													templet : '#statusTpl'
												},{
													title : '操作',
													toolbar : '#barEdit'
												} ] ],
										page : true									
									//开启分页
									});
		
							//监听工具条
							table.on('tool(LinkList)', function(obj) {
								var data = obj.data;
								if (obj.event === 'del') {
									layer.confirm('真的删除行么', function(index) {
										$.ajax({
											url :  '/link/delLinkById?id='
													+ data.id,
											type : "get",
											success : function(data) {
												if (data.code == 0) {
													layer.msg(data.msg, {
														icon : 6
													});
													obj.del();
												} else {
													layer.msg(data.msg, {
														icon : 5
													});
												}
											}
										})
										layer.close(index);
									});
								} else if (obj.event === 'edit') {
									layer.confirm('真的审核该行么', function(index) {
										$.ajax({
											url :  '/link/updateLinkByNotIsView/'
													+ data.id,
											type : "get",
											success : function(data) {
												if (data.code == 0) {
													layer.msg(data.msg, {
														icon : 6
													});
													location.reload();											
												} else {
													layer.msg(data.msg, {
														icon : 5
													});
												}
											}
										})
										layer.close(index);
									});
								}

							});

						

						

							//批量删除
							$(".batchDel")
									.click(
											function() {
												var checkStatus = table
														.checkStatus('LinkList'), data = checkStatus.data, LinkStr = '';
												if (data.length > 0) {
													$.each(data, function(n,
															value) {
														LinkStr  += value.id
																+ ',';
													});
													LinkStr  = LinkStr 
															.substring(
																	0,
																	LinkStr.length - 1);
													layer
															.confirm(
																	'确定删除<strong>'
																			+ data.length
																			+ '</strong>条数据吗？',
																	function(
																			index) {
																		//调用删除接口
																		$
																				.ajax({
																					url : '/link/delLinkStr/'
																							+ LinkStr ,//接口地址
																					type : "post",
																					success : function(
																							d) {
																						if (d.code == 0) {
																							//删除成功，刷新父页面
																							location
																									.reload();
																						} else {
																							layer
																									.msg(
																											"友情链接批量删除失败！",
																											{
																												icon : 5
																											});
																						}
																					}
																				})
																	});
												} else {
													layer.msg("请选择需要删除的友情链接");
												}
											})

						})


	</script>
</body>


</html>